import 'package:flutter_app/class/MyApp4.dart';
import 'package:flutter/material.dart';

class MyApp5 extends StatelessWidget {
  const MyApp5({super.key});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return const MaterialApp(home: StatefullApp());
  }
}

class StatefullApp extends StatefulWidget {
  const StatefullApp({super.key});

  @override
  State<StatefullApp> createState() => MyApp5Widget();
}

class MyApp5Widget extends State<StatefullApp> {
  final arrList = {
    'https://img2.baidu.com/it/u=34635369,1700394341&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1717520400&t=1090a72e239bac200595bc824ecae73e',
    'https://img0.baidu.com/it/u=3908424994,1337453330&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1717520400&t=f691eedb8fdede3b895a823315a0978f',
    'https://img0.baidu.com/it/u=412511078,2924055962&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1717520400&t=a524b7381a0b15845c78adcd0ac10fb8',
    'https://img0.baidu.com/it/u=1133762313,2060373415&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1717520400&t=43864465e6470425b83a53be55064274',
    'https://img2.baidu.com/it/u=1915228548,986941367&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1717520400&t=9ed2d61f79a52589ad707c5a1952c1e3',
  };

  List<Container> gridViewList() {
    return List<Container>.generate(
        arrList.length,
        (int index) => Container(
              margin: const EdgeInsets.all(4.0),
              child: Expanded(
                  child: Container(
                    decoration: BoxDecoration(
                        boxShadow: const [
                          BoxShadow(
                            color: Color.fromRGBO(145, 145, 145, 0.25),
                            spreadRadius: 2.0, //延伸距离,不会有模糊效果
                            blurRadius: 2.0, //延伸距离,会有模糊效果
                            offset: Offset(0.0, 0.0), //延伸的阴影，向右下偏移的距离
                          )
                        ],
                        border: Border.all(
                            width: 4.0, color: const Color.fromRGBO(145, 145, 145, 0.25)),
                        borderRadius:
                            const BorderRadius.all(Radius.circular(4.0))),
                    child: Image.network(
                      arrList.toList()[index].toString(),
                      fit: BoxFit.cover,
                    ),
                  )
              ),
            ));
  }

  Widget buildGrid() {
    return GridView.extent(
      maxCrossAxisExtent: 200,
      padding: const EdgeInsets.all(4.0),
      mainAxisSpacing: 4.0,
      crossAxisSpacing: 4.0, //列间距
      children: gridViewList(),
    );
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      title: '样式Demo5',
      home: Scaffold(
        appBar: AppBar(
          title: const Text(
            '样式Demo5',
            style: TextStyle(fontSize: 18.0),
          ),
        ),
        body: buildGrid(),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            Navigator.push(
                context, MaterialPageRoute(builder: (context) => const MyApp4()));
          },
          child: const Icon(Icons.open_in_new),
        ),
      ),
      theme: ThemeData(primaryColor: Colors.redAccent),
    );
  }
}
